#!/usr/bin/env python3
"""
图片处理主入口脚本
"""

import asyncio
import json
import sys
from pathlib import Path

# 添加项目根目录到路径
sys.path.append(str(Path(__file__).parent))

from modules.main import ImageCroppingSystem

async def main():
    """主函数"""
    if len(sys.argv) < 2:
        print("Usage: python process_images.py '<json_data>'")
        sys.exit(1)
    
    try:
        # 解析输入参数
        json_data = json.loads(sys.argv[1])
        files = json_data.get('files', [])
        config = json_data.get('config', {})
        
        # 创建处理系统
        system = ImageCroppingSystem()
        
        # 处理图片
        result = await system.process_images(files, config)
        
        # 输出结果
        print(json.dumps(result, ensure_ascii=False, indent=2))
        
    except Exception as e:
        error_result = {
            'success': False,
            'error': str(e),
            'timestamp': str(Path(__file__).stat().st_mtime)
        }
        print(json.dumps(error_result, ensure_ascii=False, indent=2))
        sys.exit(1)

if __name__ == "__main__":
    asyncio.run(main())